HOSTS ignored when disconnected [closed]

Posted by Synetech on Server Fault See other posts from Server Fault or by Synetech
Published on 2013-03-16T13:39:12Z Indexed on 2013/06/28 16:24 UTC
Read the original article Hit count: 415

Filed under:
|
|
|
|

Problem

I’m seeing a strange and extremely frustrating problem.

Any system that is not connect to the Internet (Windows 7 shows the no Internet access icon because it cannot constantly ping Microsoft’s servers) cannot even access locally hosted servers.

Hypothesis

The problem appears to be that the HOSTS file is not being used to resolve DNS entries when there are no active NICs.

Tests / Reproduction

You can reproduce it as so:

  1. Disconnect a system from the Internet (make sure all wired and wireless connections are disconnected).

  2. If necessary, add an entry to the HOSTS file (e.g., 127.0.0.1 foobar or 127.0.0.1 foobar.com)

  3. Open a command-prompt

  4. Type ping foobar or ping foobar.com

Observations

The screenshots below show a clear and demonstrative example. In the first snap, a laptop is connected to a router wirelessly. The HOSTS file has only three entries and they resolve just fine. In the second snap, the wireless radio is turned off, so the entries in the HOSTS file are ignored. Moreover, notice that pinging localhost still works even without any active NICs (as does 127.0.0.1), but it is using the IPv6 address (must be hard-coded).

You can see the same results in Windows XP with no IPv6 installed, so it has nothing to do with IPv6. I tried pining what should have resolved to 127.0.0.1 while the desktop system (with no wireless NICs) was connected via its Ethernet adapter, then again after pulling the cable from the router and waiting a couple of seconds, then again after plugging the cable back in. The same thing happens if instead of pulling out the cable, the NIC is disabled through software (the [Disable] button in the NIC’s Status dialog or via Device Manager).

Conclusions

It looks as though the HOSTS file is only being read and used if there is an active NIC, otherwise it is being ignored. This makes some sense in that if there are no active network adapters, then presumably there will not be any network activity, and thus no need to resolve host names via the HOSTS file.

This assumption is specious however because it precludes locally hosted virtual servers. The HOSTS file should be used regardless of external DNS server connectivity, otherwise you cannot use simple/consistent/testing-production names for locally hosted servers when not connected to the Internet (for example web servers; help servers for Visual Studio, 3dsmax, etc.; and so on).

Question

Does anyone know how to force Windows to use the HOSTS file even if there are no active NICs?


Appendix

Figure 1: While the wireless NIC is connected to the router (the cable-modem is in standby, so no external Internet connectivity).

Connected

Figure 2: With the wireless radio turned off (the Ethernet port is not unconnected in both cases).

Not connected

Figure 3: Same results in XP with no IPv6

XP with no IPv6

© Server Fault or respective owner

Related posts about Windows

Related posts about dns